package org.EmploiDuTemps;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.GregorianCalendar;

@SuppressWarnings("serial")
public class Week implements Serializable{
	private int weekNumber;
	private ArrayList<Day> week;
	private GregorianCalendar lastUpdate;
	private int section;
	
	public Week(int weekNumber, int section) {
		super();
		week = new ArrayList<Day>();
		this.weekNumber = weekNumber;
		this.setLastUpdate(new GregorianCalendar());
		this.section = section;
	}
	
	public ArrayList<Day> getWeek() {
		return week;
	}
	
	public void addDay(Day day){
		int index = 0; 
		for (int i = 0; i < week.size(); i++){
			if (week.get(i).getDayNumber() < day.getDayNumber())
				index = i+1;
		}
		week.add(index, day);
	}

	public int getWeekNumber() {
		return weekNumber;
	}

	public void setWeekNumber(int weekNumber) {
		this.weekNumber = weekNumber;
	}

	@Override
	public boolean equals(Object obj) {
		
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Week))
			return false;
		Week other = (Week) obj;
		if (week == null) {
			if (other.week != null)
				return false;
		} else {
			if (this.section != other.section)
				return false;
			if (week.size() == ((Week) obj).week.size()){
				for (int i = 0; i<week.size(); i++){
					if (!week.get(i).equals(((Week) obj).week.get(i))){
						return false;
					}
				}
			}
			else return false;
		}
		if (weekNumber != other.weekNumber)
			return false;
		return true;
	}

	public void setLastUpdate(GregorianCalendar lastUpdate) {
		this.lastUpdate = lastUpdate;
	}

	public GregorianCalendar getLastUpdate() {
		return lastUpdate;
	}
	
	public boolean isIncorrectWeek(){
		return getNbCoursWeek() < 0;
	}
	
	public int getNbCoursWeek(){
		int nbCoursWeek = 0;
		for(Day d:week){
			nbCoursWeek += d.getNbCours();
		}
		return nbCoursWeek;
	}

	public void setSection(int section) {
		this.section = section;
	}

	public int getSection() {
		return section;
	}
	
}
